﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NutriLeaf.Web.Core.Recipe
{
    public class RecipieIndigrident:IRecipeIngredients
    {
        public void AddIngredientToRecipe(int recipeId, int foodIngredientId, ref Model.NutriLeafDBEntities context)
        {
            Model.RecipeIndgredient r = new Model.RecipeIndgredient();
            r.RecipeID = recipeId;
            r.FoodIngredientID = foodIngredientId;
            context.RecipeIndgredients.AddObject(r);
            context.SaveChanges();
        }

        public void AddIngredientToRecipe(Model.RecipeIndgredient ingredient, ref Model.NutriLeafDBEntities context)
        {
            context.RecipeIndgredients.AddObject(ingredient);
            context.SaveChanges();
        }

        public void RemoveIngredientFromRecipe(int recipeIngredientId, ref Model.NutriLeafDBEntities context)
        {
            context.DeleteObject(context.RecipeIndgredients.Where(p => p.RecipeIngredientsID == recipeIngredientId).First());
            context.SaveChanges();
        }

        public void UpdateRecipeIngredient(Model.RecipeIndgredient ingredient, ref Model.NutriLeafDBEntities context)
        {
          Model.RecipeIndgredient indi=context.RecipeIndgredients.Where(p=>p.RecipeIngredientsID==ingredient.RecipeIngredientsID).First();
            context.RecipeIndgredients.AddObject(indi);
            context.SaveChanges();
        }

        public List<Model.RecipeIndgredient> GetAllRecipeSteps(int recipeId, ref Model.NutriLeafDBEntities context)
        {
            return context.RecipeIndgredients.Where(p => p.RecipeID == recipeId).ToList();
        }

        public Model.RecipeIndgredient GetRecipeStep(int recipeIngredientId, ref Model.NutriLeafDBEntities context)
        {
            return context.RecipeIndgredients.Where(p => p.RecipeIngredientsID == recipeIngredientId).First();
        }
    }
}